package cn.kgc.service.impl;

import cn.kgc.entity.DataDictionary;
import cn.kgc.mapper.DataDictionaryMapper;
import cn.kgc.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataDictionaryServiceImpl implements DataDictionaryService {

    @Autowired
    DataDictionaryMapper dataDictionaryMapper;


    @Cacheable(cacheNames = "data_dictionary",key = "#typeCode+'_'+#valueId")
    public DataDictionary findDataDictionary(String typeCode, Integer valueId) {
        DataDictionary dataDictionary = new DataDictionary(typeCode,valueId);
        return dataDictionaryMapper.selectOne(dataDictionary);
    }

    @Cacheable(cacheNames = "data_dictionary",key = "#typeCode")
    public List<DataDictionary> selectByType(String typeCode) {
        DataDictionary dataDictionary = new DataDictionary();
        dataDictionary.setTypeCode(typeCode);
        return dataDictionaryMapper.select(dataDictionary);
    }
}
